package com.lx.mybatis.mapper;

import com.lx.mybatis.entity.BillItem;
import com.lx.mybatis.entity.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface GoodsMapper {
    List<Goods> select(GoodsEx goods);
    @Select("select * from goods where id = #{id}")
    Goods selectById(int id);
    @Update("<script>" +
            "update goods\n" +
            "        <set>\n" +
            "            <if test=\"name != null\">\n" +
            "                name = #{name},\n" +
            "            </if>\n" +
            "            <if test=\"type != null\">\n" +
            "                type = #{type},\n" +
            "            </if>\n" +
            "            <if test=\"nums != null\">\n" +
            "                nums = #{nums},\n" +
            "            </if>\n" +
            "            <if test=\"price != null\">\n" +
            "                price = #{price},\n" +
            "            </if>\n" +
            "            <if test=\"state != null\">\n" +
            "                state = #{state},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id = #{id}" +
            "</script>")
    void update(Goods goods);
    @Update(" update goods set name = #{name}, type = #{type},  nums = #{nums}, price = #{price}, state = #{state} where id = #{id}")
    void updateAll(Goods goods);

    List<Goods> selectByIds(@Param("ids") List<Integer> ids);

    List<Goods> selectByName(@Param("name") String name,
                             @Param("op") int op);

    List<Goods> selectByType(@Param("type") String type,
                             @Param("role") String role,
                             @Param("buyed") boolean buyed,
                             @Param("sort") String sort);

    List<Map<String, Object>> selectSql(@Param("sql") String sql);

}
